home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / MOVETO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.3 KB  |  54 lines

  1.  
  2.                                             /* File       : moveto.c */
  3.                                             /* Entered by : A. Wayner */
  4.  
  5. # include <graphics.h>
  6. # include <stdlib.h>
  7.  
  8.  
  9. y[] = {1,3,5,4,6,8,5,6,8,9};
  10. x[] = {1,2,3,4,5,6,7,8,9,10};
  11. main()
  12. {
  13.     int graphdriver = DETECT, graphmode, i,
  14.     maxy = 10,  maxx = 10,
  15.     numpt, maxheight, maxwidth, xscale, yscale;
  16.  
  17.     numpt = sizeof( y ) / sizeof( int );
  18.  
  19.                                             /* Detect adapter type and */
  20.                                             /* initialize graphics system */
  21.     initgraph( &graphdriver, &graphmode, "\\turboc" );
  22.     outtextxy( 10,10, "Use of 'moveto' in scatter graph");
  23.  
  24.                                             /* Now draw the x-y graph */
  25.     maxheight = getmaxy() - 100;
  26.     yscale = maxheight / maxy;
  27.  
  28.     maxwidth = getmaxx() - 200;
  29.     xscale   = maxwidth / maxx;
  30.  
  31.     setviewport( 100, 50, 100+maxwidth, 50 + maxheight, 1 );
  32.     rectangle(0,0, maxwidth, maxheight);
  33.  
  34.     setcolor( WHITE );
  35.     settextjustify( CENTER_TEXT, CENTER_TEXT );
  36.  
  37.                                             /* Scale the data and draw an 'x' */
  38.                                             /* at each point                  */
  39.     for( i = 0; i < numpt; i++ )
  40.     {
  41.                                             /* Our y-coordinates increase as */
  42.                                             /* we go up */
  43.         moveto(x[i] * xscale, maxheight - y[i] * yscale );
  44.         outtext("X");
  45.     }
  46.  
  47.                                             /* Wait until user presses a key */
  48.     outtextxy( 10, getmaxy() - 30 ,"Press any key to exit");
  49.     getch();
  50.     closegraph();
  51.  
  52. }
  53.  
  54.